<?php
header('Content-Type: application/json');

$promptsDir = __DIR__ . '/AGENT';
$files = scandir($promptsDir);
$prompts = [];

if ($files) {
    // Sort files to ensure a consistent order
    sort($files);
    foreach ($files as $file) {
        // 支持读取.txt和.md文件
        if (in_array(pathinfo($file, PATHINFO_EXTENSION), ['txt', 'md'])) {
            $content = file_get_contents($promptsDir . '/' . $file);
            // Use filename without extension as title
            $title = pathinfo($file, PATHINFO_FILENAME);
            $prompts[] = ['title' => $title, 'content' => $content];
        }
    }
}

echo json_encode(['success' => true, 'prompts' => $prompts]);
?>